<div class="bjui-pageContent">
    <form id="announcement-edit" class="form-horizontal" method="post"  action='/announcement/edit'>
        <div class="form-group">
            <label class="col-lg-12 col-sm-12 control-label"><span class="required-span">*</span>发送对象:
            </label>
            <div class="col-lg-12 col-sm-12">
                <select class="selectpicker" data-width="750" multiple="" name="sendUsers"  data-header="请选择发送对象">
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg-12 col-sm-12 control-label"><span class="required-span">*</span>标题:
                 
            </label>
            <div class="col-lg-12 col-sm-12">
                <input type="text" class="form-control input-nm"  name="title" id="titleshow">
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg-12 col-sm-12 control-label"><span class="required-span">*</span>内容:
                 
            </label>
            <div class="col-lg-12 col-sm-12">
                <textarea name="content" id="j_form_content" class="j-content" style="width: 750px;" data-toggle="kindeditor" data-minheight="200" data-items="[
        'source', 'undo', 'redo', '|', 'preview',  'template', 'code', 'cut', 'copy', 'paste',
        'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
        'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
        'superscript', 'clearhtml', 'quickformat', 'selectall', '|', '/',
        'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
        'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|',
        'insertfile', 'table', 'hr',
         
]">
                </textarea>
            </div>
        </div>  
    </form>
</div>
<div class="btns-group bjui-pageFooter">
    <button type="button" class="close-btn">取消</button>
    <button type="submit" class="save-btn" >保存</button>
</div>
<script type="text/javascript">
   
    $(function(){
        $("[name='sendUsers']").selectpicker({
            actionsBox:true,
            deselectAllText:'取消所有选项',
            selectAllText:'选中所有选项'
        }); 
        $.ajax({
            url:"/announcement/allUser",
            type:'post',
            dataType:'json',
            success:function(data){
                $.each(data.list,function(i,item){
                    $("[name='sendUsers']").append("<option value="+item.id+">"+item.uname+"</option>")
                })
                $("[name='sendUsers']").selectpicker('render');
                $("[name='sendUsers']").selectpicker('refresh');
            }
        })
        dialog_close();
       $('#announcement-edit').find('[name="sendUsers"]').selectpicker().change(function(e) { /* Revalidate the language when it is changed */ 
            $('#announcement-edit').formValidation('revalidateField','sendUsers'); 
        }).end()
        .formValidation({
            framework: 'bootstrap', 
            excluded: ':disabled', 
            trigger:'blur',
            icon: { valid: 'glyphicon glyphicon-ok', 
            invalid: 'glyphicon glyphicon-remove', 
            validating: 'glyphicon glyphicon-refresh' }, 
            fields: {
                sendUsers: {
                    validators: {
                        notEmpty: {
                            message: '请选择发送对象'
                        }
                    }
                },
                title: {
                    validators: {
                        notEmpty: {
                            message: '请填写标题'
                        }
                    }
                },
                content: {
                    validators: {
                        notEmpty: {
                            message: '请填写内容'
                        }
                    }
                }  
            }
        })
        .on('success.form.fv', function(e) {
            // Prevent form submission
            e.preventDefault();
            // Get the form instance
            var $form = $(e.target);
            var bb=$("[name='sendUsers']").val();
            if($("[name='sendUsers']").val().length==$("[name='sendUsers'] option").length){
                $("[name='sendUsers']").selectpicker('val', '');
            }
            // Get the FormValidation instance
            var bv = $form.data('formValidation');
            // Use Ajax to submit form data
            $.post($form.attr('action'), $form.serialize(), function(result) {
                if(result.statusCode=='200' || result.statusCode=='300'){
                    BJUI.alertmsg('ok',result.message);
                    BJUI.dialog('closeCurrent');
                    BJUI.navtab('refresh', 'announcement')
                }
            }, 'json');
        }); 
    })

   
</script>
